﻿@using LanDBom.Resources
@using LanDBom.Models
@{
    ViewBag.Title = "DrawingLibrary";
}
@section styles{
    <style>
        .TablesY td:nth-child(1), .TablesY th:nth-child(1) {
            width: 50px;
        }

        .TablesY td:nth-child(2), .TablesY th:nth-child(2) {
            width: 50px;
        }

        .TablesY td:nth-child(3) {
            color: #0094ff;
        }
    </style>
}
<from class="from-horizontal">
    <div>
        <fieldset class="boun nav" style="padding-bottom:6px;">
            <legend class="len">@Resource.String155</legend>
            <div class="col-2">申请单号</div>
            <div class="col-2"><input type="text" class="input-au" id="TZK_SQDH" /></div>
            <div class="col-2">行业大类</div>
            <div class="col-2">
                <select id="TZK_hang1" class="input-au" placeholder="行业大类" name="hangye1">
                    <option value="0">--@Resource.String63--</option>
                    @foreach (var item in ViewBag.ic as List<IndustryCategory>)
                    {
                        <option value="@item.ic_id" id="CL_ID">@item.ic_name</option>
                    }
                </select>
            </div>
            <div class="col-2">行业小类</div>
            <div class="col-2">
                <select id="TZK_hang2" class="input-au" placeholder="行业小类" name="hangye1">
                    <option value="0">--@Resource.String63--</option>

                </select>
            </div>
            <div class="col-2">包装品类</div>
            <div class="col-2">
                <select id="TZK_bzpl" class="input-au" placeholder="包装品类" name="hangye1">
                    <option value="null">--@Resource.String63--</option>
                    <option value="纸质产品">纸质产品</option>
                    <option value="木制品">木制品</option>
                    <option value="塑料制品">塑料制品</option>
                    <option value="泡沫防护产品">泡沫防护产品</option>
                    <option value="可回收的">可回收的</option>
                    <option value="包装配件">包装配件</option>
                    <option value="多种材质">多种材质</option>
                    <option value="其他">其他</option>
                </select>
            </div>
            <div class="col-2">图纸类别</div>
            <div class="col-2">
                <select id="TZK_tzlb" class="input-au" placeholder="图纸类别" name="hangye1">
                    <option value="null">--@Resource.String63--</option>
                    <option value="结构图">结构图</option>
                    <option value="印刷图">印刷图</option>
                    <option value="套件">套件</option>
                    <option value="SOP(操作指导）">SOP(操作指导）</option>
                    <option value="测试报告">测试报告</option>
                    <option value="其他">其他</option>
                </select>
            </div>
            <div class="col-2">包装物名称</div>
            <div class="col-2"><input type="text" class="input-au" id="TZK_bzwmc" /></div>
            <div class="col-2">关键字搜索</div>
            <div class="col-2"><input type="text" class="input-au" id="TZK_GUANJIN" /></div>
            <div> <button id="TZK_CX" style="width:100px;margin-left:10px">查询</button><button id="TZK_DC" style="width:100px;margin-left:10px">导出EXCEL文件</button></div>
        </fieldset>
    </div>
    <div class="tab">
        <fieldset class="boun nav">
            <legend class="len">图纸信息</legend>
            <div><button id="PLXZ">批量下载</button></div>
            <div class="div_A">
                <table class="table table-sm gun TablesY" style="width: 140%; text-align-last: left ">
                    <thead class="thead-light">
                        <tr style="text-align:left">
                            <th><input type="checkbox" id="TZ_CH" /></th>
                            <th scope="col">序号</th>
                            <th scope="col">申请单号</th>
                            <th scope="col">文件名</th>
                            <th scope="col">对应物料</th>
                            <th scope="col">上传时间</th>
                            <th>行业大类</th>
                            <th>行业小类</th>
                            <th>包装类别</th>
                            <th>图纸类别</th>
                            <th>版本</th>
                            <th scope="col">上传人</th>
                            <th scope="col">操作</th>
                        </tr>
                    </thead>
                    <tbody id="AppTable" style="height:500px;">
                    </tbody>
                </table>
            </div>

        </fieldset>
    </div>
</from>
<div style="display: flex; justify-content: space-between;">
    <span>共<span id="Hangs"></span> 行</span>
    <nav aria-label="Page navigation example" class="row" style="margin-right:50px;">
        <ul class="pagination">
        </ul>
        共<span id="komdr"></span>页
    </nav>
</div>
<div id="WT_dh_mb2" style="display: none; position: absolute; border: 1px black solid; left: 25%; top: 33%; background-color: white; background-color: #f1f1f1;height:200px;width:300px">
    <div style="text-align: right; background-color: #84acde;"><span class="WT_qxbh2" style=" margin: 20px;"><i class="bi bi-x-square"></i></span></div>
    <div style="margin: 20px 10px; padding: 10px; background-color: #fff;">
        <div id="WJ_XZLJ"></div>
    </div>
    <div style="text-align:center"><button class="WT_qxbh2">@Resource.String126</button></div>
</div>
@section scripts
{
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
    <script>
        $(function () {
            $("#li16").css({ "color": "black", "background-color": "white" })
            Application_form_information(0)
            //打印申请表信息
            $(document).on("click", "#TZK_CX", function () {
                Application_form_information(0)
            })
            $(document).on("click", "#TZK_hang1",function (e) {
                var id = $(e.target).val()
                $.ajax({
                        url: "/Application/Application",
                        type: "POST",
                        data: { "CL_ID": id, "state": 10 },
                        success: function (sjik) {
                            $("#TZK_hang2 option").remove();
                            $("#TZK_hang2").append($(`<option value="0" >--@Resource.String63--</option>`));
                            $.each(sjik, function (i, item) {
                                var $tr = $(`<option value="${item.isu_id}" >${item.isu_name}</option>`);
                                $("#TZK_hang2").append($tr);
                            })
                        },
                        error: function () {
                            alert("erroer");
                        },
                    })
            })

            function Application_form_information(TNT) {
                var bian = $("#TZK_SQDH").val();
                var hydl = $("#TZK_hang1").val();
                var hyxl = $("#TZK_hang2").val();
                var bzpl = $("#TZK_bzpl").val();
                var tzlb = $("#TZK_tzlb").val();
                var bzwmc = $("#TZK_bzwmc").val();
                var Gunaj = $("#TZK_GUANJIN").val();
                $.ajax({
                    url: '/Contracts/DrawingLibrary',
                    type: 'GET',
                    data: { "bian": bian, "hydl": hydl, "hyxl": hyxl, "bzpl": bzpl, "tzlb": tzlb, "bzwmc": bzwmc, "state": 2, "TNT": TNT, "Gunaj": Gunaj },
                    success: function (datarf) {
                        var HJ = datarf * 1
                        var HNH = HJ / 20 < 1 ? 1 : Math.ceil(HJ / 20)
                        $("#Hangs").text(HJ)
                        $("#komdr").text(HNH)
                        fenye(TNT)
                        $.ajax({
                            url: '/Contracts/DrawingLibrary',
                            type: 'GET',
                            data: { "bian": bian, "hydl": hydl, "hyxl": hyxl, "bzpl": bzpl, "tzlb": tzlb, "bzwmc": bzwmc, "state": 1, "TNT": TNT - 1, "Gunaj": Gunaj },
                            success: function (data) {
                                createRow(data);
                            },
                            error: function () {
                                alert('Request Error');
                            }
                        })
                    },
                    error: function () {
                        alert('Request Error');
                    }
                })
                function createRow(data) {
                    console.log(data)
                    $('#AppTable tr').remove();
                    var index = 1
                    $.each(data, function (i, item) {
                        var x = item.De_dizhi
                        var $tr = $(`
                                 <tr>
                                 <td><input type="checkbox" class="TZ_CH"/></td>
                                     <td>${index}</td>
                                     <td class="lijin">${item.DE_shen}</td>
                                     <td>${item.DE_TZname}</td>
                                     <td>${item.HU}</td>
                                     <td>${item.De_shijian}</td>
                                    <td>${item.HD}</td>
                                    <td>${item.HX}</td>
                                    <td>${item.DE_bzpl}</td>
                                    <td>${item.DE_tzlb}</td>
                                    <td>${item.DE_BB}</td>
                                     <td>${item.De_ren}</td>
                                     <td><a href="/Contracts/Download_file?path=${x}" id="log_SZ">下载</a></td>
                                     <td style="display:none">${x}</td>
                                     <td style="display:none">${item.DE_id}</td>
                                 </tr>
                             `);
                        $('#AppTable').append($tr);
                        index++
                    })
                }
            }

            function fenye(a) {
                a = a == 0 ? 1 : a
               var hjin = a * 1
               var shunddd = $("#komdr").text() * 1
               $(".pagination li").remove()
               var $ul = ""
               $ul += (`<li class="page-item"><span class="page-link shiyong"><<<</span></li>`)
               for (var i = 1; i <= shunddd; i++) {
                   if (shunddd < 4) {
                       if (i < 5) {
                           if (hjin == i) {
                               $ul += "<li class='page-item'><span class='page-link shiyong'  style='background-color:#c4ded9'>" + i + "</span></li>";
                           } else {
                               $ul += "<li class='page-item'><span class='page-link shiyong'>" + i + "</span></li>";
                           }
                       } else {
                           $ul += "<li class='page-item'><span class='page-link'>.....</span></li>";
                           break
                       }
                   }
                   if (shunddd >= 4) {
                       if (i < (hjin - 2) || i >= (hjin + 2)) {
                           continue
                       }
                       if (i > (hjin - 2) && i < (hjin + 2)) {
                           if (hjin == i) {
                               $ul += "<li class='page-item'><span class='page-link shiyong' style='background-color:#c4ded9'>" + i + "</span></li>";
                           } else {
                               $ul += "<li class='page-item'><span class='page-link shiyong'>" + i + "</span></li>";
                           }
                       } else {
                           $ul += "<li class='page-item'><span class='page-link'>.....</span></li>";
                       }
                   }
               }
               $ul += (`<li class="page-item"><span class="page-link shiyong">>>></span></li>`);
               $(".pagination").append($ul)
           }
            $(document).on("click", ".shiyong,.subsed", function () {
                var sjind = $(this).text()
                var shunddd = $("#komdr").text()
                sjind = sjind == "<<<" ? 1 : sjind == ">>>" ? shunddd : sjind * 1
                Application_form_information(sjind)
            })
            $(document).on("click", ".lijin", function (e) {
                var DTon = $(e.target).parent().children().eq(2).text()
                console.log(DTon)
                var name = $("#Login_N").text()
                window.location.href = "/Application/Application?App_ban=" + DTon + "&Nameed=" + name + "&name=" + "设计委托";
            })
            $(document).on("click", "#TZ_CH", function (e) {
                if ($("#TZ_CH").prop("checked") == true) {
                    console.log(1)
                    $(".TZ_CH").prop("checked", true)
                }
                else {
                    $(".TZ_CH").prop("checked", false)
                }
            })
            $(document).on("click", "#TZK_DC", function () {
                var CG_XX = [];
                var WT_RZ = [];
                var check = $("input[class=TZ_CH]:checked").parent().parent().length;
                if (check <= 0) {
                    alert("至少选中一行！");
                }
                else {
                    $("input[class=TZ_CH]:checked").parent().parent().each(function (index, obj) {
                        CG_XX.push({
                            AP_bian: $("td[class='lijin']", obj).text()
                        })

                    })
                    console.log("共" + CG_XX.length + "数据");
                    console.log(CG_XX);
                    var Employee_path = $("#Login_path").text()
                    console.log(Employee_path)

                     var userInput = prompt("请输入文件名：", "");
                     if (userInput != null) {
                         $.ajax({
                             url: "/Application/TuZPLExcel",
                             type: 'POST',
                             data: { "application": CG_XX, "ades": userInput },
                             success: function (text) {
                                 $("#WT_dh_mb2").css({ "display": "block" })
                                 $("#WJ_XZLJ").append($(`<a href="/Contracts/Download_file?path=${text}" id="log_SZ" class="WT_qxbh2">下载</a>`))
                             },
                             error: function (text) {
                                 alert("系统错误");
                             }
                         })
                     }
                }
            })
            $(document).on("click", ".WT_qxbh2", function () {
                $("#WT_dh_mb2").css({ "display": "none" })
                $("#WJ_XZLJ a").remove()
            })
            $(document).on("click", "#PLXZ", function () {
                var IDSS=""
                var check = $("input[class=TZ_CH]:checked").parent().parent().length;
                if (check <= 0) {
                    alert("至少选中一行！");
                }
                else {
                    var encodedData = "";
                    $("input[class=TZ_CH]:checked").parent().parent().each(function (index, obj) {
                        encodedData += $(obj).children().last().text()+","
                    })
                    //// 将数组序列化为JSON字符串，并进行URL编码
                    $("#WT_dh_mb2").css({ "display": "block" })
                    console.log(encodedData)
                    $("#WJ_XZLJ").append($(`<a href="/Contracts/DownloadFile?list1=${encodeURIComponent(encodedData)}" id="log_SZ" class="WT_qxbh2">下载</a>`));
                    //// 更新URL并重定向
                    //window.location.href = "/Contracts/DownloadFile?list=" + encodedData;
                    /*$.ajax({
                        url: "/Contracts/DownloadFile",
                        type: 'POST',
                        data: { "list": CG_XX },
                        success: function (text) {
                            alert(text)
                            
                        },
                        error: function (text) {
                            alert("系统错误");
                        }
                    })*/
                }
            })
        })
    </script>
}